﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArcannEngine.Entities
{
    public class Element
    {
        public float fuelContainer;
        public float weight;
        public List<Engine> engines;
        public RocketEntity rocket;
        public bool disconnected = false;

        public Element(RocketEntity rocket, float weight, float fuelCapacity)
        {
            this.rocket = rocket;
            fuelContainer = fuelCapacity;
            engines = new List<Engine>();
            this.weight = weight;
        }

        public void addEngine(Engine.EngineType type, float value)
        {
            Engine engine = null;
            switch (type)
            {
                case Engine.EngineType.REGULAR:
                    {
                        engine = new Engine(this, type, value);
                        break;
                    }
                case Engine.EngineType.STARTER:
                    {
                        engine = new Engine(this, type, value);
                        break;
                    }
                default:
                    break;
            }
                engines.Add(engine);
        }

        public float calculateForce(int time)
        {
            float result = 0;
            if (getWeight() > weight)
            for (int i = 0; i < engines.Count(); i++)
            {
                result += engines[i].run(time);
            }
            return result;
        }

        public float getWeight()
        {
            if (fuelContainer < 0) fuelContainer = 0;
            return fuelContainer + weight;
        }
    }
}
